home *** CD-ROM | disk | FTP | other *** search
/ PC World Komputer 2010 April / PCWorld0410.iso / pluginy Firefox / 4490 / 4490.xpi / components / scripts / yahoo.js < prev   
Encoding:
JavaScript  |  2010-01-14  |  7.3 KB  |  226 lines

  1. /***********************************************************
  2. Yahoo
  3. ***********************************************************/
  4.  var supportInboxOnly=true;
  5.  var supportShowFolders=true;
  6.  
  7. function init(){
  8.   this.initStage=ST_PRE;
  9.   var ar=this.user.split("@");
  10.   if(ar[1]=="yahoo.co.jp"){
  11.     this.loginData=["https://login.yahoo.co.jp/config/login?",
  12.                         "","passwd","login="+encodeURIComponent(ar[0])];
  13.     this.dataURL="http://mail.yahoo.co.jp/"
  14.     this.mailURL="http://mail.yahoo.co.jp/";
  15.     this.mailDomain="mail.yahoo.co.jp";
  16.     this.domain="yahoo.co.jp";
  17.     if(this.getCookie("yahoo.co.jp","Y")!=null)this.loginData[3]+="&.persistent=y";
  18.   }else{
  19.     this.loginData=["https://login.yahoo.com/config/login?",
  20.                         "login","passwd"];
  21.     this.dataURL="http://mail.yahoo.com/"
  22.     this.mailURL="http://mail.yahoo.com/";
  23.     this.mailDomain="mail.yahoo.com";
  24.     this.domain="yahoo.com";    
  25.     if(this.getCookie("yahoo.com","Y")!=null)this.loginData[3]+="&.persistent=y";
  26.   }
  27. }
  28.  
  29. function process(aHttpChannel, aData) {
  30.   switch(this.stage){
  31.   case ST_PRE:
  32.     this.mode=-1;
  33.     this.getHtml(this.dataURL);
  34.     return false;
  35.   case ST_PRE_RES:
  36.     this.stage=ST_LOGIN;
  37.     break;
  38.   case ST_LOGIN_RES:
  39.     var fnd=aData.match(/<input.+?type="hidden".+?name=".secdata".+?value="(.+?)".*?>/);
  40.     if(fnd){
  41.       if(this.main.prefBranch.getBoolPref("yahoo.showCaptcha")){
  42.         var rs=this.main.openCaptchaDialog(this.id,this.user,"https://ab.login.yahoo.com/img/"+fnd[1]+".jpg");
  43.         if(rs){
  44.           this.getHtml(this.loginData[LOGIN_URL],this.loginData[LOGIN_POST]+"&.secdata="+encodeURIComponent(fnd[1])+"&.secword="+encodeURIComponent(rs));
  45.           return false;
  46.         }
  47.       }
  48.       /*var ck=this.getCookieString("yahoo.com","F");
  49.       if(ck){
  50.         this.cookieManager.addCookies("http://login.yahoo.com",ck);
  51.         this.getHtml(this.loginData[LOGIN_URL],this.loginData[LOGIN_POST]);
  52.         return false;
  53.       }*/
  54.       this.onError();
  55.       return true;
  56.     }
  57.     this.stage=ST_DATA;
  58.     break;
  59.   case (ST_LOGIN_RES+1):
  60.     this.stage=ST_DATA;
  61.     break;
  62.   case (ST_DATA_RES):
  63.     var fnd=aData.match(/doAction\(\'2\',\s*?\'(\S+?)\'/);
  64.     if(fnd){//not supported os
  65.       try{
  66.         var location=aHttpChannel.getResponseHeader("Location");
  67.         location=location.match(/\S+yahoo.com/);
  68.         this.getHtml(location+"/dc/system_requirements.php","a=2&crumb="+encodeURIComponent(fnd[1]));
  69.         return false;
  70.       }catch(e){}
  71.     }
  72.     break;
  73.   case (ST_DATA_RES+1):
  74.     this.stage=ST_DATA;
  75.     break;
  76.   }
  77.   return this.baseProcess(aHttpChannel, aData);
  78. }
  79. /*
  80. //without this, keep asking captcha code
  81. function onRequest(aHttpChannel){
  82.   WebMailHandler.prototype.onRequest.call(this,aHttpChannel);
  83.   if(this.stage==this.initStage){
  84.     var ck=this.getCookieString("yahoo.com","F");
  85.     if(ck)this.cookieManager.addCookies(aHttpChannel.URI,ck);
  86.   }
  87. }
  88. */
  89. //without this, keep asking captcha code
  90. function onRequest(aHttpChannel){
  91.   WebMailHandler.prototype.onRequest.call(this,aHttpChannel);
  92.   if(this.stage==this.initStage){
  93.     var done=false;
  94.     try{
  95.       var s=this.main.prefBranch.getCharPref("accounts."+this.id+"."+this.user+".cookie");
  96.       s=s.split("\t");
  97.       var ioService = Components.classes["@mozilla.org/network/io-service;1"]
  98.                       .getService(Components.interfaces.nsIIOService);
  99.       var uri=ioService.newURI(s[0],null,null);
  100.       this.cookieManager.addCookies(uri,s[1]);
  101.       done=true;
  102.     }catch(e){}
  103.     if(!done){
  104.       var ck=this.getCookieString(this.domain,"F");
  105.       if(ck){      
  106.         this.cookieManager.addCookies("http://login."+this.domain,ck);
  107.       }
  108.     }
  109.     
  110. /*    if(!done){
  111.       var ck=this.getCookieString("yahoo.com","F");
  112.       if(ck){
  113.         this.cookieManager.addCookies(aHttpChannel.URI,ck);
  114.         this.main.prefBranch.setCharPref("accounts."+this.id+"."+this.user+".cookie",aHttpChannel.URI.spec+"\t"+ck);
  115.       }
  116.     }*/
  117.   }
  118. }
  119. function onResponse(aHttpChannel){
  120. /*  try {
  121.       var cookie = aHttpChannel.getResponseHeader("Set-Cookie");
  122. if(cookie.match(/^F=/m))dout(this.stage+"###"+this.user+" "+cookie);      
  123.   }catch(e){}*/
  124.   WebMailHandler.prototype.onResponse.call(this,aHttpChannel);
  125.   if(this.stage==(ST_LOGIN_RES+1)){
  126.     var s=this.cookieManager.findCookie(aHttpChannel.URI.spec,"F");
  127.     if(s){
  128.       this.main.prefBranch.setCharPref("accounts."+this.id+"."+this.user+".cookie",aHttpChannel.URI.spec+"\t"+s);
  129.     }
  130.   }
  131. }
  132. function getCount(aData){
  133.   return this.mailCount;
  134. }
  135. function getData(aData){
  136.   var obj={};
  137.   var ar=[];
  138.   this.folders={};//used for direct link
  139.   if(this.mode<0){
  140.     var fnd=aData.match(/<div.+?folderlist.+?>([\s\S]+?)<div class=\"last\">/);
  141.     this.mode=fnd?1:0;
  142.   }
  143.   if(this.mode==1){//original mode
  144.     var fnd=aData.match(/<div.+?folderlist.+?>([\s\S]+?)<div class=\"last\">/);
  145.     fnd=fnd[1];
  146.     if(!this.inboxOnly||this.showFolders){
  147.       var fnd2=aData.match(/<div.+?customfolders.+?>([\s\S]+?)<div class=\"last\">/);
  148.       if(fnd2){
  149.         fnd+=fnd2[1];
  150.       }
  151.     }
  152.     fnd=fnd.match(/<li .+?<\/a>/g);
  153.     if(fnd){
  154.       var s;
  155.       var num=0;
  156.       for each(s in fnd){
  157.         var t=s.match(/li\s+id=\"(.+?)\".+?<a.+?>(?:<em>)?(.+?)(?:\s\S+(\d+)\S+)?<\/a>/);
  158.         if(t){
  159.           if(t[1]=="draft"||t[1]=="sent"||t[1]=="receipt"
  160.             ||t[1]=="bulk"||t[1]=="trash")continue;
  161.           var n=0;
  162.           if(t[3])n=parseInt(t[3]);
  163.           if(this.inboxOnly){
  164.             if(t[1]=="inbox")num=n;
  165.           }else num+=n;
  166.           if(n>0&&t[1]!="inbox"){
  167.             var fid=t[1];
  168.             if(fid.indexOf("%")==0)fid=fid.substring(1,fid.length-1);
  169.             this.folders[t[2]]=fid;
  170.             ar.push(t[2]);
  171.             ar.push(n);
  172.           }
  173.         }
  174.       }
  175.       this.mailCount=num;
  176.       if(this.showFolders){
  177.         if(ar)obj.folders=encodeArray(ar);
  178.       }
  179.       return obj;
  180.     }
  181.   }else{
  182.     fnd=aData.match(/<ListFoldersResponse>([\s\S]+?)<\/ListFoldersResponse>/);
  183.     if(fnd){
  184.       fnd=fnd[1].match(/<folder.+?<\/folder>/g);
  185.       if(fnd){
  186.         var s;
  187.         var num=0;
  188.         for each(s in fnd){
  189.           s=s.match(/unread=\\?\"(\d+)\\?\".+?fid=\\?\"(.+?)\\?\".+?name=\\?\"(.+?)\\?\"/);          
  190.           if(s){
  191.             if(s[2]=="%40B%40Bulk"||s[2]=="Draft"
  192.               ||s[2]=="Sent"||s[2]=="Trash")continue;
  193.             var n=0;
  194.             if(s[1])n=parseInt(s[1]);
  195.             if(this.inboxOnly){
  196.               if(s[2]=="Inbox")num=n;
  197.             }else num+=n;
  198.             if(n>0&&s[2]!="Inbox"){
  199.               var name=s[3];
  200.               name=unescape(name.replace(/&#x(\w+);/g,function(){return "%u"+RegExp.$1;}));
  201.               ar.push(name);
  202.               ar.push(n);
  203.             }            
  204.           }
  205.         }
  206.         this.mailCount=num;
  207.         if(this.showFolders){
  208.           if(ar)obj.folders=encodeArray(ar);
  209.         }
  210.         return obj;
  211.       }
  212.     }
  213.   }
  214.   this.mailCount=-1;
  215.   return obj;
  216. }
  217. function getMailURL(aFolder){
  218.   if(this.mode==1&&aFolder&&this.dataURLCopy){
  219.     var n=this.dataURLCopy.indexOf("/",7);
  220.     var url=this.dataURLCopy.substring(0,n)
  221.               +"/mc/showFolder?fid="+encodeURIComponent(this.folders[aFolder]);
  222.     return url;
  223.   }
  224.   return this.mailURL;  
  225. }
  226.